<?php

namespace App\Http\Controllers\Home;
use Hash;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;


class LoginController extends Controller
{	

	//注册的时候解析模板
    public function register(){

    return view('home.login.register');
    }
    //发送短信验证
     public function sendmessage(Request $request){

     $phone = $request->input('phone');

    $code =  rand(1000,9999);

    session(['codes'=>$code]);

    $options['accountsid']='ed8e0cdd33c9b8c1acfde18b78d16b08';
    $options['token']='33f1a749fd9d2319293512a0782da7df';

     $ucpass = new \Ucpaas($options);
    // 初始化 $options必填
    
    // 开发者账号信息查询默认为json或xml

    $ucpass->getDevinfo('xml');
    $appId = "af911a3353164976b1182843e2a997ca";
    $to = $phone;
    $templateId = "31463";
    // $code=rand(1000,9999);
    $param="狗蛋网,".$code.",3";

    $res =$ucpass->templateSMS($appId,$to,$templateId,$param);
        
    if($res){
        echo 1;
    }else{
        echo 0;
    }

        }
    //注册的信息的接受验证 执行注册

    public function doregister(Request $request){


    	//检测手机号验证码是否正确
        $vcode =$request->input('vcode');
        $codes = session('codes');
        if($vcode != $codes){

            return back()->with("输入验证码有误");
        }

    	//验证码正确才能往下走
    	$res=$request->only(['username','phone']);
    	$res['password']=Hash::make($request->input('passwrod'));
    	$res['token']=str_random(50);
    	

    	// 执行添加操作
    	$ress= DB::table('user')->insert($res);
    	if($ress){

    	//这里跳转到网页的主页面去;
            return redirect('/');
    	}else{

    		return  back()->with('error','注册失败联系管理员');
    	}


    }


    //发送短信验证

    public function send(){
      
    }


   


  
}
